package com.lyf.scm.common.util;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.lyf.scm.common.enums.BaseOtherTargetEnum;
import com.lyf.scm.common.enums.OtherTargetsEnum;
import com.lyf.scm.common.enums.PurchaseOrderTargetEnum;
import com.lyf.scm.common.enums.TiSsEnum;

import java.io.IOException;

/**
 * 枚举反序列化
 *
 * @author wangchlei
 * @date 2020/11/24
 */
public class BaseOtherTargetEnumConverter extends JsonDeserializer<BaseOtherTargetEnum> {

    @Override
    public BaseOtherTargetEnum deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
        String enumName = p.getText();
        for (TiSsEnum item : TiSsEnum.values()) {
            if (item.toString().equals(enumName)) {
                return item;
            }
        }
        for (PurchaseOrderTargetEnum item : PurchaseOrderTargetEnum.values()) {
            if (item.toString().equals(enumName)) {
                return item;
            }
        }
        for (OtherTargetsEnum item : OtherTargetsEnum.values()) {
            if (item.toString().equals(enumName)) {
                return item;
            }
        }
        return null;
    }
}
